class Item extends eui.Component implements eui.UIComponent {
	public constructor(val: number, onClick: any, x : number, y : number) {
		super();
		let self = this;
		self._val = val;
		self._onClick = onClick;
		self._posX = x;
		self._posY = y;
		self._width = 80;
		self._height = 80;
		self.getColor();
	}
	protected partAdded(partName: string, instance: any): void {
		super.partAdded(partName, instance);
	}
	protected childrenCreated(): void {
		super.childrenCreated();
		this.init();
	}

	public _posX : number;
	public _posY : number;

	public itemBtn: eui.Group;
	public img_state1: eui.Image;
	public img_state2: eui.Image;

	public get width(){ return this._width;}
	public get height(){return this._height;}

	public get val(){ return this._val; }
	public set val(num : number){
		let self = this;
		self._val = num;
		self.getColor();
		self.setShowSprite();
	}

	public swapeItem(item : Item){
		let self = this;
		let posx = item._posX;
		let posy = item._posY;

		item._posX = self._posX;
		item._posY = self._posY;
		
		self._posX = posx;
		self._posY = posy;
	}

	public clear(){
		let self = this;
		self._val = -1;
		self.img_state1.texture = null;
		self.img_state2.texture = null;
	}
	
	public _color : string;
    private getColor(){
        let self = this;
        switch(self._val){
            case 1:
                self._color = "红";
                break;
            case 2:
                self._color = "棕";
                break;
            case 3:
                self._color = "黄";
                break;
            case 4:
                self._color = "绿";
                break;
            case 5:
                self._color = "蓝";
                break;
            case 6:
                self._color = "紫";
                break;
            case 7:
                self._color = "白";
                break;
        }
    }

	private init() {
		let self = this;
		self.img_state2.visible = false;
		self.setShowSprite();
	}

	private setShowSprite(){
		let self = this;
		self.setImg(self.img_state1, self.getName1());
	}

	private setImg(img: eui.Image, name: string) {
		img.source = name;	
	}

	private getName1(): string {
		return "type_" + String(this.val) + "0_png";
	}

	private getName2(): string {
		return "type_" + String(this.val) + "1_png";
	}

	private _val: number;
	private _onClick: any;

	private _width : number;
	private _height : number;
}